package com.bj.jiufu.base.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;
import net.sf.json.util.JSONUtils;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class JcaiHandlerInterceptor implements HandlerInterceptor
{
	public boolean preHandle(HttpServletRequest req, HttpServletResponse resp,
			Object obj) throws Exception {

		String msg=req.getParameter("msg");

		if(null==msg||msg.equals("")||!JSONUtils.mayBeJSON(msg))
		{
			return false;
		}
		JSONObject msgObj =  JSONObject.fromObject(msg);

		Object header = msgObj.get("header");

		Object body = msgObj.get("body");

		req.setAttribute("content", msgObj);

		return true;
	}

	/**
	 *
	 */
	public void postHandle(HttpServletRequest req, HttpServletResponse resp,
			Object obj, ModelAndView view) throws Exception {
		System.out.println(123123);

	}

	/**
	 *
	 */
	public void afterCompletion(HttpServletRequest req,
			HttpServletResponse resp, Object postHandle, Exception exception)
			throws Exception {
	}

}
